<?php

require_once 'base.php';

class Users extends Base {

    function __construct() {
        parent::__construct();
        $this->load->model('members');
    }

    function index() {

        
        $temp['data'] = $this->members->getAll();
        $temp['title'] = 'Users';
        $temp['view'] = 'users/register_view';
        $this->load->view('main', $temp);
    }

    function register_view() {
        // $this->load->model('members');
        
        $temp['data'] = $this->members->general();
        $temp['title'] ="Register";
        $temp['view'] = 'users/register_view';
        $this->load->view('main', $temp);
    }

    function registration() {
        $this->form_validation->set_rules('username', 'User Name', 'trim|required|min_length[4]|xss_clean');
        $this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
        if ($this->form_validation->run() == FALSE) {
               // index();
           $this-> register_view();
        }
        else {
            $data = array(
                'group_id' => 0,
                'username' => $this->input->post('username'),
                'name' => $this->input->post('name'),
                'email' => $this->input->post('email'),
                'password' => md5($this->input->post('password'))
            );
            $this->load->model('members');
            $this->members->add_user($data);
            $temp['title'] = 'Users';
            $temp['view'] = 'users/addsuccess';
            $temp['data'] = $data;
            $this->load->view('main', $temp);
        }
    }
    function list_uses()
    {
        
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
